<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Gass_apply extends CI_Controller {
  function __construct() {
    parent::__construct();
		// Load required CI libraries and helpers.
		$this->load->database();
		$this->load->library('session');
 		$this->load->helper('url');
 		$this->load->helper('form');

  	// IMPORTANT! This global must be defined BEFORE the flexi auth library is loaded! 
 		// It is used as a global that is accessible via both models and both libraries, without it, flexi auth will not work.
		$this->auth = new stdClass;

		// Load 'standard' flexi auth library by default.
		$this->load->library('flexi_auth');	
    $this->config->load('gass_conf');
		// Check user is logged in as an admin.
		// For security, admin users should always sign in via Password rather than 'Remember me'.
		if (! $this->flexi_auth->is_logged_in_via_password() || ! $this->flexi_auth->is_admin()) {
			// Set a custom error message.
			$this->flexi_auth->set_error_message(urlencode('学生用户没有访问这个部分的操作权限！'), TRUE);
			$this->session->set_flashdata('message', $this->flexi_auth->get_messages());
			redirect('gass_auth');
		}

		// Note: This is only included to create base urls for purposes of this demo only and are not necessarily considered as 'Best practice'.
		$this->load->vars('base_url', $this->config->item('base_url'));
		$this->load->vars('includes_dir', $this->config->item('includes_dir'));
		$this->load->vars('current_url', $this->uri->uri_to_assoc(1));
		
		// Define a global variable to store data that is then used by the end view page.
		$this->data = null;
		//$this->output->enable_profiler(TRUE);
	  }
	  
	/**
	 * 对学生申请信息的数据聚合
	 * 
	 * 研招办老师可以看到所有学生的申请情况以及各专业学院老师的审批情况
	 * 专业学院招生老师只能对报考本学院的学生申请进行审批
	 */ 
	function manage_apply()
	{
	 $this->load->model('gass_apply_model');
	 if (! $this->flexi_auth->is_privileged('apply_a')){
		$this->session->set_flashdata('message', '<p class="error_msg">您没有浏览、操作学生申请信息的权限，请与系统管理员联系！</p>');
    redirect('gass_auth_teachers');
	 }
	 if ($this->input->post('search_key_words') || $this->input->post('select_news_status') || $this->input->post('select_college') || $this->input->post('select_news_type')) {
		$search_query = str_replace(' ','-',$this->input->post('search_key_words'));
		if(empty($search_query)) $search_query="0000";
		redirect('gass_apply/manage_apply/search_key_words/'.$search_query.'/select_news_status/'.$this->input->post('select_news_status').'/select_college/'.$this->input->post('select_college').'/select_news_type/'.$this->input->post('select_news_type').'/page/');
	 }
   $this->gass_apply_model->get_apply_list();
    
   $this->data['stuGender'] = $this->config->item('gass_xbm');		
   $this->data['stuNation'] = $this->config->item('gass_mzm');	
   $this->data['stuPolitionStatus'] = $this->config->item('gass_zzmmm');	
   $this->data['stuApplyType'] = $this->config->item('gass_apply_type');	 
   $this->data['stuApplyRom'] = $this->config->item('gass_tmzg');	
   //$this->data['stuFrom'] = $this->config->item('gass_kslym');	
   
   $this->data['stuApplyStatus'] = $this->config->item('gass_apply_status');	  
   $this->data['stuApplyType'] = $this->config->item('gass_apply_type');
   $this->data['colleges_list'] = $this->gass_global_model->get_colleges_array();
   
	 $this->data['message'] = (! isset($this->data['message'])) ? $this->session->flashdata('message') : $this->data['message'];		
          // 对系统报错信息（p标签包裹的数据）进行重新处理；        
          if (!empty($this->data['message']))
          {
              $this->data['alert_message'] = $this->gass_global_model->get_alert_message($this->data['message']);   
          } 
	 $this->load->view('gass_teachers/a_search_view', $this->data);
	}
	/**
	 * 浏览操作学生申请信息的数据聚合页面
	 * 
	 * 研招办老师对提交审核的信息进行审批，若审批通过，则由专业学院老师进行审核。
	 * 研招办老师可随时退回提交的审核信息，并说明退回缘由。
	 */ 
	function apply_details($appId)
	{
	 $this->load->model('gass_apply_model');
	 if (! $this->flexi_auth->is_privileged('apply_v'))
	 {
		$this->session->set_flashdata('message', '<p class="error_msg">您没有浏览学生申请细节的权限，请与系统管理员联系！</p>');
    redirect('gass_auth_teachers');
	 }
	 if($this->input->post('pass_button_name')){
		$this->gass_apply_model->authorized_apply($appId);
	 }
	 if($this->input->post('back_button_name')){
	 	$this->gass_apply_model->return_apply($appId);
	 }
				
		$this->data['applyDetailsInfo'] = $this->gass_apply_model->apply_details($appId);
		$this->data['stuGender'] = $this->config->item('gass_xbm');		
    $this->data['stuNation'] = $this->config->item('gass_mzm');	
    $this->data['stuPolitionStatus'] = $this->config->item('gass_zzmmm');	
    $this->data['stuApplyType'] = $this->config->item('gass_apply_type');	 
    $this->data['stuApplyRom'] = $this->config->item('gass_tmzg');	
    $this->data['stuFrom'] = $this->config->item('gass_kslym');	
    $this->data['stuCertifyType'] = $this->config->item('gass_zjlxm');	
    $this->data['stuApplyStatus'] = $this->config->item('gass_apply_status');	        
		// Set any returned status/error messages.
		$this->data['message'] = (! isset($this->data['message'])) ? $this->session->flashdata('message') : $this->data['message'];	
          // 对系统报错信息（p标签包裹的数据）进行重新处理；        
          if (!empty($this->data['message']))
          {
              $this->data['alert_message'] = $this->gass_global_model->get_alert_message($this->data['message']);   
          } 
		$this->load->view('u_apply_details_view', $this->data);
	}
}
